#Author: Lukasz Kufel (qfel13)

#=============META===========================
class MetaObject(object):
	""" abstrakcyjna klasa z ktorej dziedzicza wszystkie inne obiekty"""
	def __init__(self, oid, name):
		self.type = "meta"
		self.oid = oid #object identifier identyfikator obiektu
		self.name = name #object name nazwa obiektu
		self.pointedByList = []

	def pointedBy(self,  me):
		if not me in self.pointedByList:
			self.pointedByList.append(me)

	def __repr__(self):
#		return "oid: %s, name: %s" % (str(self.oid), str(self.name))
		return '|%d|%s|' % (self.oid, str(self.name))

#===============ATOMIC=========================
class AtomicObject(MetaObject):
	def __init__(self, id, name,  value=None):
		MetaObject.__init__(self, id, name)
		self.type = "atomic"
		self.value = value

	def setValue(self,  value):
		"""ustawianie value robie to przez set alby 
		pozniej moc dodac sprawdzanie poprawnosci danych"""
		self.value = value

	def __repr__(self):
		return MetaObject.__repr__(self) + str(self.value)

#===============POINTER=========================
class PointerObject(MetaObject):
	def __init__(self, id, name, objectId = None):
		MetaObject.__init__(self, id, name)
		self.type = "pointer"
		self.ptr = objectId

	def setPtr(self,  objectId):
		self.ptr = objectId

	def __repr__(self):
		return MetaObject.__repr__(self) + '-->'+ str(self.ptr)

#==============COMPLEX==========================
class ComplexObject(MetaObject):
	def __init__(self, id, name):
		MetaObject.__init__(self, id, name)
		self.type = "complex"
		self.childrenList = {}
		self.level = 1

	def addChild(self,  obj):
		if obj.name not in self.childrenList.iterkeys():
			self.childrenList[obj.oid] = obj

	def __repr__(self):
		toReturn = MetaObject.__repr__(self) + 'children:' + self.childrenList.keys().__repr__() + ' '
		for child in self.childrenList.itervalues():
			
			toReturn += '\n'
#			for i in range(self.level):
#				toReturn += '\t'
			toReturn += self.level * '\t'
			if isinstance(child, ComplexObject):
				child.level += 1
			toReturn += child.__repr__()
		return toReturn

#==============ALL OBJECTS==========================
class AllObjects(ComplexObject):
#	def __repr__(self):
#		return self.childrenList.__repr__()
#		return MetaObject.__repr__(self) + ', childrenList: ' + self.childrenList.keys().__repr__()
	pass

#==============MAIN==========================
if __name__ == '__main__':
    a = MetaObject(1, "a")
    b = AtomicObject(2,  "b",  2)
    c = PointerObject(3,  "c",  2)
    d = ComplexObject(4,  "d")
    d.addChild(c)
    d.addChild(c)
    d.addChild(b)
    d.addChild(b)
    d.addChild(a)
    print '\n' + repr(a) + '\n' + repr(b) + '\n' + repr(c) + '\n' + repr(d)
    
